//
//  TSCVCMy.m
//  Tsc_IOS
//
//  Created by Rio on 15-5-15.
//  Copyright (c) 2015年 idream. All rights reserved.
//

#import "TSCVCMy.h"
#import "TSCConstants.h"

@interface TSCVCMy ()

@end

@implementation TSCVCMy

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 初始化属性
    _ud = [NSUserDefaults standardUserDefaults];
    _dialog = nil; // 暂时指向空，当使用时再赋值
//    _nvc = [self navigationController]; // 不使用的原因请见.h文件注释
    _inputDic = _inputDic == nil ? [NSDictionary dictionary] : _inputDic; // 注：不能直接指向新dic，因为getVCInput()将先执行，在此进行初始化将覆盖getVCInput()中的结果
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

/**
 * 显示状态提示dialog，比如“正在提交...正在查询...”
 *
 * @date 2015-05-16
 * @author Rio
 */
- (void) showDialogWithResourceKey:(NSString *)resourceKey isProcessing:(BOOL) isProcessing {
    [self showDialogWithString:NSLocalizedString(resourceKey, nil) isProcessing:isProcessing];
}

/**
 * 显示状态提示dialog，比如“正在提交...正在查询...”
 *
 * @date 2015-06-03
 * @author Rio
 */
- (void) showDialogWithString:(NSString *)string isProcessing:(BOOL)isProcessing {
    _dialog = [[TSCMyDialog alloc]init];
    if (isProcessing) {
        _dialog.processingMsgText = string;
    } else {
        _dialog.msgText = string;
    }
    [_dialog show];
}

/**
 * 关闭状态提示dialog
 *
 * @date 2015-05-16
 * @author Rio
 */
- (void) dissmisDialog {
    if(_dialog) {
        [_dialog dismiss];
    }
}

//
/**
 * 作用：
 * 1. 所有的子类都通过这个@selector接收上一个vc发来的“你要解析输入参数啦！”的消息，并进行vc间输入参数的解析
 * 2. 在父类中声明该方法，可以使子类vc在发送消息时，不再报找不到@selector的warning信息
 *
 * @date 2015-05-29
 * @author Rio
 */
- (void) getVCInput:(NSNotification *) notification {
    // 解析并设置输入参数
    // 注：原来持有的参数不能丢，比如从A->B，再从B->A时，A中的参数不能丢
//    _inputDic = [notification object];
    NSMutableDictionary * newInputDic = [NSMutableDictionary dictionaryWithDictionary:_inputDic];
    [newInputDic addEntriesFromDictionary:notification.object];
    _inputDic = [NSDictionary  dictionaryWithDictionary:newInputDic];
    
    // 每次接收到消息后，都将自己从监听者队列移除，确保不会因为多次调用addObserver()方法而被多次调用
    [[NSNotificationCenter defaultCenter]removeObserver:self name:notification.name object:nil];
    
    NSLog(@"[D]VC[%@]接收到输入参数：%@", self, _inputDic);
}

@end
